package com.game.user;


import java.nio.ByteBuffer;
import java.util.concurrent.ConcurrentLinkedQueue;

import com.game.NioSocket.Gsocket;

public class User extends xobj implements Cloneable{
	private Gsocket socket;//user套接字通道
	
	private String name="";//username
	

	/**游戏角色列表*/
	public static final ConcurrentLinkedQueue<User> userOnLine = new ConcurrentLinkedQueue<User>(); 
	
	/**
	 * 
	 * @param name
	 * @return
	 */
	public static User getUserByName(String name){
		User user=null;
		for(User uu:userOnLine){
			if(uu.getName().equals(name)){
				user=uu;
			}
		}
		return user;
	}
	
	
	public Gsocket getSocket() {
		return socket;
	}

	public void setSocket(Gsocket socket) {
		this.socket = socket;
	}
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}
	@Override
	public void putdata(ByteBuffer buffer) {
		// TODO Auto-generated method stub
		this.getSocket().writeData(buffer);
	}
	
	@Override
	public User clone(){
		User user=null;
		try {
			user=(User) super.clone();
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user;
		
	}
}
